/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Functions;

import Factory.Tables.Cart;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Airwyn
 */
public class ProgramFunction {
    
    
    public static String convertWebDateFormatToMySQLDateFormat(String stringDate){
        SimpleDateFormat format = new SimpleDateFormat(SystemTime.WebDateFormat);
        Date date = null;
        try{
            date = format.parse(stringDate);
            
        }
        catch(Exception ex){
            Logger.getLogger(ProgramFunction.class.getName()).log(Level.SEVERE, null, ex);
        }  
        return new SimpleDateFormat(SystemTime.MySQLDateFormat).format(date);
    }
    
    
    public static String convertMySQLDateFormatToWebDateFormat(String stringDate){
        SimpleDateFormat format = new SimpleDateFormat(SystemTime.MySQLDateFormat);
        Date date = null;
        try{
            date = format.parse(stringDate);
            
        }
        catch(Exception ex){
            Logger.getLogger(ProgramFunction.class.getName()).log(Level.SEVERE, null, ex);
        }  
        return new SimpleDateFormat(SystemTime.WebDateFormat).format(date);
    }
    
    public static String convertMySQLTimeFormatToWebTimeFormat(String time){
        SimpleDateFormat format = new SimpleDateFormat(SystemTime.MySQLTimeFormat);
        Date date = null;
        try{
            date = format.parse(time);
            
        }
        catch(Exception ex){
            Logger.getLogger(ProgramFunction.class.getName()).log(Level.SEVERE, null, ex);
        }  
        return new SimpleDateFormat(SystemTime.WebTimeFormat).format(date);
    }
    
    
    public float countTotalPrice(ArrayList<Cart> cart){
        float totalPrice = 0f;
        if(cart!=null){
            Iterator<Cart> iter = cart.iterator();
            Cart tempCart;
            while(iter.hasNext()){
                tempCart = iter.next();
                totalPrice+=tempCart.getMovie().getPrice() * tempCart.getQuantity();
            }
        } 
        return Float.parseFloat(String.format("%.2f",totalPrice));
    }
    
}
